package com.nys.cqhttp.message.factory.impl;

import com.nys.cqhttp.message.factory.IMessageHandler;
import com.nys.cqhttp.model.Massage;
import com.nys.cqhttp.param.Context;
import com.nys.cqhttp.util.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.List;

/**
 * DirectUrlMessageHandler
 *
 * @author nysheng
 * @version 1.0.0
 * @description 服务器
 * @date 2021/12/28 19:53
 */
@Slf4j
public class FWQ2MessageHandler implements IMessageHandler {

  @Override
  public List<String> listHandler(Massage messagePojo, Context context) {
    return Arrays.asList(handler(messagePojo, context));
  }

  @Override
  public String handler(Massage messagePojo, Context context) {
    RestTemplate restTemplate = SpringContextUtil.getBean("restTemplate");
    String[] split = context.getMessageParam().getMessage().split("-");
    String url = String.format(messagePojo.getValue(), split[1]);
    try {
              restTemplate.getForEntity(url, String.class).getBody();
      return "执行成功";
    } catch (Exception e) {
      return null;
    }
  }
}
